home *** CD-ROM | disk | FTP | other *** search
/ ftp.hitl.washington.edu / ftp.hitl.washington.edu.tar / ftp.hitl.washington.edu / pub / people / tsoper / CT Explorer / OpenGLSliceDrawer.cs < prev    next >
Text File  |  2005-06-09  |  2KB  |  100 lines

  1. using System;
  2. using CsGL.OpenGL;
  3. using SampleGUI;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Collections;
  7. using System.Windows.Forms;
  8.  
  9. public enum DRAW_METHOD
  10. {
  11.     GRIDDED_SQUARES,    
  12.     PIXELATED_SQUARES,
  13.     POINTS
  14. }
  15. public class SliceDrawer
  16. {
  17.     private ElementIndexer3D indexer;
  18.     public ElementIndexer3D Indexer
  19.     {
  20.         get
  21.         {
  22.             return indexer;
  23.         }
  24.         set
  25.         {
  26.             indexer = value;
  27.         }
  28.     }
  29.  
  30.  
  31.     public DRAW_METHOD DrawMethod; 
  32.  
  33.     //constructor
  34.     public SliceDrawer()
  35.     {
  36.     }
  37.  
  38.     //change to 
  39.     public void DrawSlice(Scan s, int normalAxis)
  40.     {
  41.         //define axis that are coplanar with the slice
  42.         AXIS[] planarAxes = new AXIS[2];
  43.         int[] dim = new int[2];
  44.         //float[] pixelScale = new float[3]; //scale pixels for gridded databy dim+1/dim
  45.         int idx = 0;
  46.  
  47.         indexer.RCPIndex = s.DimensionSize;
  48.         //TO DO: Figure out how to match up low res and high res images
  49.         for(int i = 0; i < 3; i++)
  50.         {
  51.             if(i != (int)normalAxis)
  52.             {
  53.                 planarAxes[idx] = (AXIS)i;
  54.                 dim[idx] = Math.Abs(indexer.GetXYZElement((int)planarAxes[idx]));
  55.                 if(DrawMethod.Equals(DRAW_METHOD.GRIDDED_SQUARES))
  56.                 {
  57.             //        pixelScale[i] = dim[idx]/(float)(dim[idx]-1); 
  58.                     dim[idx]--;
  59.                 }
  60.             //    else
  61.             //        pixelScale[i] = 1.0f;
  62.                 idx++;
  63.             }
  64.             //else
  65.             //    pixelScale[i] = 1.0f; //pixel scale in orthogonal direction is always 1
  66.         }
  67.  
  68.         //get size in x,y,z
  69.         indexer.RCPIndex = s.DimensionSize;
  70.  
  71.         float gray;
  72.         int window = s.Window;
  73.         int level = s.Level;
  74.         int[] di = {0,0,1,1};    //index offsets for each of the 4 corners
  75.         int[] dj = {0,1,1,0};    //index offsets for each of the 4 corners
  76.  
  77.         indexer.RCPIndex = s.SliceIndex;
  78.         for(int i = 0; i < dim[0]; i++)    //iterate through scan matrix dimension 1
  79.         {
  80.             for(int j = 0; j < dim[1]; j++)    //iterate through scan matrix dimension 2
  81.             {
  82.                 GL.glBegin(GL.GL_QUADS);
  83.                 for(int k = 0; k < 4; k++)    //iterate through each corner of the quad
  84.                 {
  85.                     indexer.SetXYZElement((int)planarAxes[0],i+di[k]);
  86.                     indexer.SetXYZElement((int)planarAxes[1],j+dj[k]);
  87.                     if(DrawMethod.Equals(DRAW_METHOD.GRIDDED_SQUARES) || k.Equals(0))
  88.                     {
  89.                         gray = s.Data[indexer.Row,indexer.Column,indexer.Plane];
  90.                         gray = (gray-(level-window/2))/(float)window;
  91.                         GL.glColor3f(gray,gray,gray);
  92.                     }
  93.                     GL.glVertex3f(indexer.X,indexer.Y,indexer.Z);
  94.                 }//for k
  95.                 GL.glEnd();
  96.             }//for j
  97.         }//for i
  98.     }//DrawSlice
  99.  
  100. }